<template>
  <div>
    <el-table :data="exchangeRates" :loading="query.loading" border style="width: 100%">
      <el-table-column prop="id" label="编号" width="100" />
      <el-table-column prop="abbr" label="简称" width="220" />
      <el-table-column prop="name" label="币种" />
      <el-table-column prop="exchangeRate" label="汇率" />
      <el-table-column prop="updatedOn" label="更新时间" />
      <el-table-column label="操作" width="120">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="showHistory(scope.row.abbr)">汇率历史</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { ExchangeRate } from '@/store/api'

export default {
  created() {
    this.list(this.query)
  },
  data() {
    return {
      query: {
        loading: true
      },
      exchangeRates: []
    }
  },
  methods: {
    list(query) {
      this.query.loading = true
      return ExchangeRate.list(query).then(list => {
        this.exchangeRates = list
        this.query.loading = false
      })
    },
    showHistory(abbr) {
      this.$router.push({
        name: 'exchange-rate-history',
        params: { abbr: abbr }
      })
    }
  }
}
</script>
